"use strict";
/* Controllers */
app.controller("dqcConfigListController", ['$scope', '$compile' , '$location', '$rootScope', '$routeParams', 'dqcConfigListService', function ($scope, $compile, $location, $rootScope, $routeParams, dqcConfigListService) {

    var vm = $scope.vm;

    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listDqcConf = function () {
        var vm = $scope.vm;
        var params = {};
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        dqcConfigListService.listDqcConf(params,procFn, errorFn);
    };

    $scope.initializeController = function () {
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $scope.listDqcConf();
    };

    $scope.initializeController();


    $scope.confirmDel=function(id,index){
        vm.toDelId=id;
        vm.toDelIndex=index;
        $('#myModal').modal('show')
    };

    $scope.ok=function(){
        var vm = $scope.vm;
        console.log("toDelId"+vm.toDelId);
        console.log("toDelIndex"+vm.toDelIndex);
        var params = {};
        params.id=vm.toDelId;
        params.deleted=2;
        var procFn = function (response) {
            if (response.success && response.data) {
               $('#list_table').bootstrapTable('remove', {
                   field:'id',
                   values:[vm.toDelId]
               });
               alert("删除成功！")
            } else {
               alert(response.msg);
            }
        };
        dqcConfigListService.delDqcConf(params, procFn, errorFn);
        $('#myModal').modal('hide')
    }

}]);

function dqcConfigOpt(value, row, index) {
        var optCont='<a type="button" class="btn btn-xs btn-danger" onclick=angular.element(this).scope().confirmDel('+ row.id +','+index+') >删除</a>\n'
        var optCont2='<a type="button" class="btn btn-xs btn-primary" href="#/sre/dqc/dqc_config/edit/'+row.id+'" target="_blank">修改</a>'
        return [
            optCont,
            optCont2
        ].join('');
}




/* Services */
app.service('dqcConfigListService', ['ajaxService', function (ajaxService) {

    this.listDqcConf = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dqc/listDqcConfig.do", successFunction, errorFunction);
    };

    this.delDqcConf = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dqc/delDqcConfig.do", successFunction, errorFunction);
    };

}]);
